package com.example.movie_shop.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

@Configuration
public class FileUploadConfig {

    @Value("${file.upload-path}")
    private String uploadPath;

    @Bean
    MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory mcf = new MultipartConfigFactory();
        mcf.setMaxFileSize(DataSize.parse("100MB"));
        mcf.setMaxRequestSize(DataSize.parse("200MB"));
        mcf.setLocation(uploadPath);
        return mcf.createMultipartConfig();
    }
}
